package com.fanshilz.flower2025.apps.admin.collect.controller;

import com.fanshilz.flower2025.apps.admin.collect.req.ProjectCollectTableReq;
import com.fanshilz.flower2025.apps.admin.collect.resp.ProjectCollectTableDetailResp;
import com.fanshilz.flower2025.business.flower.projectCollect.service.IProjectCollectService;
import com.fanshilz.flower2025.framework.resp.Resp;
import com.fanshilz.flower2025.framework.resp.TableResp;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/collect")
public class CollectController {

    @Resource
    private IProjectCollectService projectCollectService;

    @PostMapping("/table")
    public Resp<TableResp<ProjectCollectTableDetailResp>> table(@RequestBody @Valid ProjectCollectTableReq req) {
        Page<ProjectCollectTableDetailResp> page = projectCollectService.getMapper().paginateWithRelationsAs(Page.of(req.getCurrent(), req.getPageSize(), req.getTotal()),
                QueryWrapper.create(), ProjectCollectTableDetailResp.class);
        return Resp.success(new TableResp<>(page.getRecords(), page.getTotalRow()));
    }

}
